import request from '..'

// 发送邮箱验证码
const sendMessageRequest = async email => {
  const result = await request({
    method: 'post',
    url: '/user/send',
    data: {
      email,
    },
  })
  return result
}
// 注册
const registerUserRequest = async user => {
  const { user_email, user_password, user_nickname, code } = user
  const result = await request({
    method: 'post',
    url: '/user/register',
    data: {
      user_email,
      user_password,
      user_nickname,
      code,
    },
  })
  return result
}
// 登录
const loginUserReuqest = async user => {
  const { user_email, user_password } = user
  const result = await request({
    method: 'post',
    url: '/user/blog/login',
    data: {
      user_email,
      user_password,
    },
  })
  return result
}
// 修改个人信息
const updateProfileRequest = async info => {
  const result = await request({
    method: 'patch',
    url: '/user/update_info',
    data: { info },
  })
  return result
}
// 获取个人信息
const queryUserInfoRequest = async id => {
  const result = await request({
    method: 'get',
    url: `/user/info/${id}`,
  })
  return result
}
// 上传头像
const uploadAvatarRequest = async formdata => {
  const result = await request({
    method: 'post',
    url: `/upload/avatar`,
    data: formdata,
    headers: { 'Content-Type': 'multipart/form-data' },
  })
  return result
}
// 获取作者简介
const queryAuthorRequest = async () => {
  const result = await request({
    method: 'get',
    url: `/user/author`,
  })
  return result
}

export {
  sendMessageRequest,
  registerUserRequest,
  loginUserReuqest,
  updateProfileRequest,
  queryUserInfoRequest,
  uploadAvatarRequest,
  queryAuthorRequest,
}
